import React from 'react';
import './App.css';
import { HashRouter as Router, Switch, Route } from 'react-router-dom';
import Page1 from 'pages/Page1';
const routes = [
    {
        path: '/',
        component: Page1,
    },
]
function RouteWithSubRoutes(route: any) {
    return (
        <Route
            path={route.path}
            render={(props) => <route.component {...props} routes={route.routes}>
                {route.children ? route.children.map((child: any, i: any) => (
                    /** 递归传入子组件 */
                    <RouteWithSubRoutes key={i} {...child} />
                )) : ''}
            </route.component>}
        />
    );
}
function App() {
  return (
    <div className="App">
      <Router>
                <div style={{ width: '100%' }}>
                    <Switch>
                        {routes.map((route, i) => (
                            <RouteWithSubRoutes key={i} {...route} />
                        ))}
                    </Switch>
                </div>
            </Router>
    </div>
  );
}

export default App;
